// WaferJobSelectionDlg.cpp : implementation file
//
#include "stdafx.h"
#include "dstaperemove.h"
#include "WaferJobSelectionDlg.h"
#include "Util/MinUtilExt.h"
#include "DataManager/CMappingData.h"

#ifdef _DEBUG
#define new DEBUG_NEW
#undef THIS_FILE
static char THIS_FILE[] = __FILE__;
#endif

/////////////////////////////////////////////////////////////////////////////
// CWaferJobSelectionDlg dialog


CWaferJobSelectionDlg::CWaferJobSelectionDlg(CMappingData* pMappingData, CDMControlCenter* pDMCC,CWnd* pParent /*=NULL*/)
	: CDialog(CWaferJobSelectionDlg::IDD, pParent)
{
	//{{AFX_DATA_INIT(CWaferJobSelectionDlg)
		// NOTE: the ClassWizard will add member initialization here
	//}}AFX_DATA_INIT
	m_lnkMappingData = pMappingData;


}


void CWaferJobSelectionDlg::DoDataExchange(CDataExchange* pDX)
{
	CDialog::DoDataExchange(pDX);
	//{{AFX_DATA_MAP(CWaferJobSelectionDlg)
	DDX_Control(pDX, IDB_CANCEL, m_bExit);
	DDX_Control(pDX, IDB_ALL_SELECT, m_bAllSelect);
	DDX_Control(pDX, IDB_ALL_CANCEL, m_bAllCancel);
	//}}AFX_DATA_MAP
	
	DDX_Control(pDX, IDB_WAFER_BUTTON1, m_bWaferJobSel[0]);
	DDX_Control(pDX, IDB_WAFER_BUTTON2, m_bWaferJobSel[1]);
	DDX_Control(pDX, IDB_WAFER_BUTTON3, m_bWaferJobSel[2]);
	DDX_Control(pDX, IDB_WAFER_BUTTON4, m_bWaferJobSel[3]);
	DDX_Control(pDX, IDB_WAFER_BUTTON5, m_bWaferJobSel[4]);
	DDX_Control(pDX, IDB_WAFER_BUTTON6, m_bWaferJobSel[5]);	
	DDX_Control(pDX, IDB_WAFER_BUTTON7, m_bWaferJobSel[6]);
	DDX_Control(pDX, IDB_WAFER_BUTTON8, m_bWaferJobSel[7]);
	DDX_Control(pDX, IDB_WAFER_BUTTON9, m_bWaferJobSel[8]);	
	DDX_Control(pDX, IDB_WAFER_BUTTON10, m_bWaferJobSel[9]);
	DDX_Control(pDX, IDB_WAFER_BUTTON11, m_bWaferJobSel[10]);
	DDX_Control(pDX, IDB_WAFER_BUTTON12, m_bWaferJobSel[11]);
	DDX_Control(pDX, IDB_WAFER_BUTTON13, m_bWaferJobSel[12]);
	DDX_Control(pDX, IDB_WAFER_BUTTON14, m_bWaferJobSel[13]);
	DDX_Control(pDX, IDB_WAFER_BUTTON15, m_bWaferJobSel[14]);
	DDX_Control(pDX, IDB_WAFER_BUTTON16, m_bWaferJobSel[15]);	
	DDX_Control(pDX, IDB_WAFER_BUTTON17, m_bWaferJobSel[16]);
	DDX_Control(pDX, IDB_WAFER_BUTTON18, m_bWaferJobSel[17]);
	DDX_Control(pDX, IDB_WAFER_BUTTON19, m_bWaferJobSel[18]);	
	DDX_Control(pDX, IDB_WAFER_BUTTON20, m_bWaferJobSel[19]);
	DDX_Control(pDX, IDB_WAFER_BUTTON21, m_bWaferJobSel[20]);
	DDX_Control(pDX, IDB_WAFER_BUTTON22, m_bWaferJobSel[21]);
	DDX_Control(pDX, IDB_WAFER_BUTTON23, m_bWaferJobSel[22]);
	DDX_Control(pDX, IDB_WAFER_BUTTON24, m_bWaferJobSel[23]);
	DDX_Control(pDX, IDB_WAFER_BUTTON25, m_bWaferJobSel[24]);
}


BEGIN_MESSAGE_MAP(CWaferJobSelectionDlg, CDialog)
	//{{AFX_MSG_MAP(CWaferJobSelectionDlg)
	ON_BN_CLICKED(IDB_ALL_SELECT, OnAllSelect)
	ON_BN_CLICKED(IDB_ALL_CANCEL, OnAllCancel)
	ON_BN_CLICKED(IDB_WAFER_BUTTON1, OnWaferButton1)
	ON_BN_CLICKED(IDB_WAFER_BUTTON2, OnWaferButton2)
	ON_BN_CLICKED(IDB_WAFER_BUTTON3, OnWaferButton3)
	ON_BN_CLICKED(IDB_WAFER_BUTTON4, OnWaferButton4)
	ON_BN_CLICKED(IDB_WAFER_BUTTON5, OnWaferButton5)
	ON_BN_CLICKED(IDB_WAFER_BUTTON6, OnWaferButton6)
	ON_BN_CLICKED(IDB_WAFER_BUTTON7, OnWaferButton7)
	ON_BN_CLICKED(IDB_WAFER_BUTTON8, OnWaferButton8)
	ON_BN_CLICKED(IDB_WAFER_BUTTON9, OnWaferButton9)
	ON_BN_CLICKED(IDB_WAFER_BUTTON10, OnWaferButton10)
	ON_BN_CLICKED(IDB_WAFER_BUTTON11, OnWaferButton11)
	ON_BN_CLICKED(IDB_WAFER_BUTTON12, OnWaferButton12)
	ON_BN_CLICKED(IDB_WAFER_BUTTON13, OnWaferButton13)
	ON_BN_CLICKED(IDB_WAFER_BUTTON14, OnWaferButton14)
	ON_BN_CLICKED(IDB_WAFER_BUTTON15, OnWaferButton15)
	ON_BN_CLICKED(IDB_WAFER_BUTTON16, OnWaferButton16)
	ON_BN_CLICKED(IDB_WAFER_BUTTON17, OnWaferButton17)
	ON_BN_CLICKED(IDB_WAFER_BUTTON18, OnWaferButton18)
	ON_BN_CLICKED(IDB_WAFER_BUTTON19, OnWaferButton19)
	ON_BN_CLICKED(IDB_WAFER_BUTTON20, OnWaferButton20)
	ON_BN_CLICKED(IDB_WAFER_BUTTON21, OnWaferButton21)
	ON_BN_CLICKED(IDB_WAFER_BUTTON22, OnWaferButton22)
	ON_BN_CLICKED(IDB_WAFER_BUTTON23, OnWaferButton23)
	ON_BN_CLICKED(IDB_WAFER_BUTTON24, OnWaferButton24)
	ON_BN_CLICKED(IDB_CANCEL, OnCancel)
	ON_BN_CLICKED(IDB_WAFER_BUTTON25, OnWaferButton25)
	//}}AFX_MSG_MAP
END_MESSAGE_MAP()

/////////////////////////////////////////////////////////////////////////////
// CWaferJobSelectionDlg message handlers

void CWaferJobSelectionDlg::OnAllSelect() 
{
	// TODO: Add your control notification handler code here
	for(int i=0; i<MAX_WAFER; i++)
	{
		m_bWaferJobSel[i].SetColor(YELLOW);
		m_WaferJobSelectFlag[i] = TRUE;
		m_lnkMappingData->SetMappingData(i,TRUE);
	}
}

void CWaferJobSelectionDlg::OnAllCancel() 
{
	// TODO: Add your control notification handler code here
	for(int i=0; i<MAX_WAFER; i++) 
	{
		m_bWaferJobSel[i].SetColor(LTGRAY);
		m_WaferJobSelectFlag[i] = FALSE;
		m_lnkMappingData->SetMappingData(i,FALSE);
	}
}

void CWaferJobSelectionDlg::OnCancel() 
{
	// TODO: Add your control notification handler code here
	int i,t = 0;

	for (i=0 ;i <25 ; i++)
	{
		if (m_lnkMappingData->GetMappingData(i))
		{
			t = t +1;
		}
	}
	m_lnkMappingData->SetMappingCount(t);
	m_lnkMappingData->SetWaferCountData(t);
	if (t>0)
	{
		m_lnkMappingData->SetWaferSelection(TRUE);
	}
	else
	{
		m_lnkMappingData->SetWaferSelection(FALSE);
	}
	CDialog::OnCancel();
}

BOOL CWaferJobSelectionDlg::OnInitDialog() 
{
	CDialog::OnInitDialog();
	// TODO: Add extra initialization here
	m_bExit.SetTextSize(10,TRUE);
	m_bAllSelect.SetTextSize(10,TRUE);	
	m_bAllCancel.SetTextSize(10,TRUE);

	for(int i=0; i<MAX_WAFER; i++)
	{
		m_WaferJobSelectFlag[i] = FALSE;
		m_bWaferJobSel[i].SetColor(LTGRAY);
		m_bWaferJobSel[i].SetTextSize(10,TRUE);
		m_WaferJobSelectFlag[i] = FALSE;
		m_lnkMappingData->SetMappingData(i,FALSE);
	}
		
	return TRUE;  // return TRUE unless you set the focus to a control
	              // EXCEPTION: OCX Property Pages should return FALSE
}
void CWaferJobSelectionDlg::WaferJobSelect(int sel)
{
	if( !m_WaferJobSelectFlag[sel] ) 
	{
		m_WaferJobSelectFlag[sel] = TRUE;
		m_bWaferJobSel[sel].SetColor(YELLOW);
		m_lnkMappingData->SetMappingData(sel,TRUE);
		
	}
	else 
	{
		m_WaferJobSelectFlag[sel] = FALSE;
		m_bWaferJobSel[sel].SetColor(LTGRAY);
		m_lnkMappingData->SetMappingData(sel,FALSE);
		
	}
}
void CWaferJobSelectionDlg::OnWaferButton1() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(0);
}

void CWaferJobSelectionDlg::OnWaferButton2() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(1);
}

void CWaferJobSelectionDlg::OnWaferButton3() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(2);
}

void CWaferJobSelectionDlg::OnWaferButton4() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(3);
}

void CWaferJobSelectionDlg::OnWaferButton5() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(4);
}

void CWaferJobSelectionDlg::OnWaferButton6() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(5);
}

void CWaferJobSelectionDlg::OnWaferButton7() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(6);
}

void CWaferJobSelectionDlg::OnWaferButton8() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(7);
}

void CWaferJobSelectionDlg::OnWaferButton9() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(8);
}

void CWaferJobSelectionDlg::OnWaferButton10() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(9);
}

void CWaferJobSelectionDlg::OnWaferButton11() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(10);
}

void CWaferJobSelectionDlg::OnWaferButton12() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(11);
}

void CWaferJobSelectionDlg::OnWaferButton13() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(12);
}

void CWaferJobSelectionDlg::OnWaferButton14() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(13);
}

void CWaferJobSelectionDlg::OnWaferButton15() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(14);
}

void CWaferJobSelectionDlg::OnWaferButton16() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(15);
}

void CWaferJobSelectionDlg::OnWaferButton17() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(16);
}

void CWaferJobSelectionDlg::OnWaferButton18() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(17);
}

void CWaferJobSelectionDlg::OnWaferButton19() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(18);
}

void CWaferJobSelectionDlg::OnWaferButton20() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(19);
}

void CWaferJobSelectionDlg::OnWaferButton21() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(20);
}

void CWaferJobSelectionDlg::OnWaferButton22() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(21);
}

void CWaferJobSelectionDlg::OnWaferButton23() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(22);
}

void CWaferJobSelectionDlg::OnWaferButton24() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(23);
}

void CWaferJobSelectionDlg::OnWaferButton25() 
{
	// TODO: Add your control notification handler code here
	WaferJobSelect(24);
}
